package de.dfki.asr.genesis2.sms.oauth;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TwitterOAuth
 */
@WebServlet("/twoauth")
public class TwitterOAuth extends OAuthServlet {
	private static final long serialVersionUID = 1L;
	
    public static final String TWITTER_REQUEST_TOKEN_SESSION = "TWITTER_REQUEST_TOKEN_SESSION";
    public static final String TWITTER_ACCESS_TOKEN_SESSION = "TWITTER_ACCESS_TOKEN_SESSION";
    //protected static final String redirect_uri = "http://localhost:8080/sms/TwitterOAuthService";
    protected static final String redirect_uri = "http%3A%2F%2Flocalhost%3A8080%2Fsms%2FTwitterOAuthService";
    protected static final String client_id = "ILyOZn3hJDue8cRePFH94w";
	protected static final String client_secret = "9zHE8QRaaIsJwJlSCLuJVik9hv6plgVZS45G2lg";
	protected static final String accessToken_url = "hhttps://api.twitter.com/oauth/access_token?";
	protected static final String requestCode_url = "https://api.twitter.com/dialog/oauth/request_token?";
	protected static final String authorize_url = "https://api.twitter.com/oauth/authorize?";
       
    /**
     * @see OAuthServlet#OAuthServlet()
     */
    public TwitterOAuth() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		++stateIncrementer;
		
		String ip = request.getRemoteAddr();
		
		String url = requestCode_url + 
					 "oauth_consumer_key=" + client_id +
					 "&oauth_nonce=" + client_secret +
					 "&oauth_callback=" + redirect_uri;
		
		System.out.println(url);
		
		response.getWriter().write("redirect_uri=" + url);		 
		
		response.sendRedirect(url);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
